import 'babel-polyfill'
import 'classlist-polyfill'

import Vue from 'vue'
import axios from './router/axios'
import VueAxios from 'vue-axios'
import App from './App'
import { preventReClick } from '@/util/plugins';
import './const/icons' // icon
import './permission' // 权限
import './error' // 日志
import router from './router/router'
import store from './store'
import { loadStyle } from './util/util'
import * as urls from '@/config/env'
import { iconfontUrl, iconfontVersion } from '@/config/env'
import * as filters from './filters' // 全局filter
import ElementUI from 'element-ui'
import Echarts from 'echarts'
import 'element-ui/lib/theme-chalk/index.css'
import './styles/common.scss'
import avueFormDesign from 'avue-plugin-formdesign'
import basicContainer from './components/basic-container/main'
// 插件 json 展示
import vueJsonTreeView from 'vue-json-tree-view'

import check from './util/test.js'
import { filterParams } from "@/util/tools"

import global_ from './util/message.js'

import Print from '@/plugs/print.js'

// 图片查看器
import duoImageViewer from 'duo-image-viewer'

Vue.use(duoImageViewer)

Vue.prototype.globalData = global_
Vue.prototype.$echarts = Echarts
Vue.use(router)
Vue.use(Print)

Vue.use(avueFormDesign);
Vue.use(vueJsonTreeView)

Vue.use(VueAxios, axios)

Vue.use(check)

Vue.use(ElementUI, {
  size: 'mini',
  menuType: 'text'
})
ElementUI.Table.props.stripe = {
  default: true,
  type: Boolean
}
// 修改表头样式
ElementUI.Table.props.headerCellClassName = {
  default: 'miui-header-cell-style',
  type: String
}

ElementUI.TableColumn.props.headerAlign = {
  default: 'center',
  type: String
}

ElementUI.TableColumn.props.align = {
  default: 'center',
  type: String
}

Vue.use(window.AVUE, {
  size: 'medium',
  menuType: 'text'
})

// 添加全局方法：过滤表单的空字段及字符串中的空格
Vue.prototype.filterParams = filterParams

// 注册全局容器
Vue.component('basicContainer', basicContainer)

// 加载相关url地址
Object.keys(urls).forEach(key => {
  Vue.prototype[key] = urls[key]
})

// 加载过滤器
Object.keys(filters).forEach(key => {
  Vue.filter(key, filters[key])
})

// 动态加载阿里云字体库
iconfontVersion.forEach(ele => {
  loadStyle(iconfontUrl.replace('$key', ele))
})

Vue.config.productionTip = false

// 动态改变meta标签，更改PC端与移动端屏幕分辨率
router.beforeEach((_to, _from, next) => {
  let head = document.getElementsByTagName("head");
  let metaR = document.getElementById('remove')
  if(metaR){
    head[0].removeChild(metaR)
  }
  if(_to.path == '/login' || _to.path == '/dept'){
    let meta = document.createElement("meta");
    meta.name = 'viewport'
    meta.content = 'width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no';
    meta.id = 'remove'
    head[0].appendChild(meta);
  }else{
    let meta = document.createElement("meta");
    meta.name = 'viewport'
    meta.content = 'width=device-width, initial-scale=0, maximum-scale=1, user-scalable=yes';
    meta.id = 'remove'
    head[0].appendChild(meta);
  }
  next();
});

new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')
